package com.cqs.leetcode.math;

import com.cqs.leetcode.ds.ArraysUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * lixw
 * 2021/11/4
 **/
public class HammingDistance461 {


    public int hammingDistance(int x, int y) {
        int cnt = 0;
        while (x > 0 || y > 0) {
            int lx = x % 2;
            int ly = y % 2;
            x = x >> 1;
            y = y >> 1;
            cnt += lx ^ ly;
        }
        return cnt;
    }

    public static void main(String[] args) {
        HammingDistance461 h = new HammingDistance461();
        List<int[]> cases = new ArrayList<>();
        cases.add(new int[]{1,4});
        cases.add(new int[]{3,1});
        for (int[] c : cases) {
            System.out.println(ArraysUtils.formatInts(c) + "\t --> " + h.hammingDistance(c[0],c[1]));
        }


    }
}
